import { fileURLToPath, URL } from 'node:url';

import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import Components from 'unplugin-vue-components/vite';
import { VantResolver } from '@vant/auto-import-resolver';

// https://vitejs.dev/config/
const config = defineConfig(({ command }) => {
  const baseConfig = {
    plugins: [
      vue(),
      Components({
        resolvers: [VantResolver()]
      })
    ],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url))
      }
    }
  };
  if (command === 'build') {
    return {
      ...baseConfig,
      base: './'
    };
  } else {
    return {
      ...baseConfig,
      server: {
        host: '0.0.0.0'
      },
      base: '/'
    };
  }
});

export default config;
